﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;

namespace CoreEx.DynamicInvoker.Implementation
{
    
                                   
    public abstract class MethodFactoryBase<TMember> : DynamicFactoryBase<TMember>  where TMember :MethodBase
    {
        protected override void LoadInstance(ILGenerator iLGenerator, TMember member)
        {
            if (!member.IsStatic)
            {
                iLGenerator.Emit(OpCodes.Ldarg_0);
                if (member.DeclaringType.IsValueType)
                    iLGenerator.Emit(OpCodes.Unbox, member.DeclaringType);                                                
            }
        }
        
        
        public override IEnumerable<Type> GetParameters(TMember member)
        {
            return member.GetParameters().Select(p => p.ParameterType);            
        }
    }
}
